
#pragma once
#include "Event.h"
#include "EventLoop.h"
#include "db/miscstorage.h"
#include "hbase.h"
#include "htime.h"
#include "singleton.h"
#include <map>
#include <memory>
#include <string>

namespace zx {

#define AUTH_TOKEN_DEP  "20240820"
#define AUTH_CZGW_TOKEN "zxfz 车载网关连接"
#define TIME_INTERVAL   (1 * 3600 * 1000)  //1hour

class Auth {
    SINGLETON_DECL(Auth)

public:
    Auth();
    ~Auth();

    void update_token(hv::EventLoopPtr loop);
    std::string gen_token(std::string user);
    // 仅超级用户
    bool user_register(std::string user, std::string password);
    bool user_modify(std::string user, std::string password);
    std::vector<std::string> user_get(void);
    bool user_delete(std::string user);
    // 所有用户
    bool login(std::string user, std::string password);
    bool logout(std::string user);

    bool is_admin_login(std::string token);
    bool is_user_login(std::string token);
    bool is_czgw_login(std::string token);

private:
    std::string get_current_date();
    std::string m_token_dep;
    std::string m_czgw_token;
    std::unordered_map<std::string, std::string> m_logins;
};
}  // namespace zx

#define AuthHandler zx::Auth::instance()
